package com.itunic.cloud.domain;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.oauth2.core.user.OAuth2User;

import java.util.Collection;
import java.util.Map;

/**
 * 定制的OAuth2User对象
 * 此处仅为了演示，提供了轻量级的定制。
 *
 * @author Sean
 */
@Data
public class CustomOAuth2User implements OAuth2User {
    /**
     * 用户id
     */
    private String id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 用户所拥有的权限
     */
    private Collection<SimpleGrantedAuthority> authorities;
    private Map<String, Object> attributes;

    @Override
    public <A> A getAttribute(String name) {
        return (A) attributes.get(name);
    }

    @Override
    public Map<String, Object> getAttributes() {
        return attributes;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getName() {
        return username;
    }
}
